package hotel.modal;

import hotel.dao.RoomGoodsDao;
import javafx.beans.property.*;

public class RoomGoods extends Goods {
	private SimpleIntegerProperty roomGoodsId;	// 房间物品编号
	private SimpleStringProperty roomNo;		// 所属房间编号
	private SimpleStringProperty registerTime;	// 登记时间
	private SimpleBooleanProperty valid;		// 有效标记
	private SimpleStringProperty comment;		// 备注信息
	
	private void init(RoomGoodsDao rgd) {
		if(rgd != null) {
			this.roomGoodsId = new SimpleIntegerProperty(rgd.getRoomGoodsId());
			this.roomNo = new SimpleStringProperty(rgd.getRoomNo());
			this.registerTime = new SimpleStringProperty(rgd.getRegisterTime());
			this.valid = new SimpleBooleanProperty(rgd.isValid());
			this.comment = new SimpleStringProperty(rgd.getComment());
		}else {
			this.roomGoodsId = new SimpleIntegerProperty(0);
			this.roomNo = new SimpleStringProperty("0");
			this.registerTime = new SimpleStringProperty("");
			this.valid = new SimpleBooleanProperty(true);
			this.comment = new SimpleStringProperty("");
		}
	}
	
	public RoomGoods(RoomGoodsDao rgd) {
		super(rgd.getGoods());
		init(rgd);
	}
	
	public RoomGoods() {
		super();
		init((RoomGoodsDao)null);
	}
	
	public Object getDao() {
		RoomGoodsDao rgd = new RoomGoodsDao();
		rgd.setRoomGoodsId(roomGoodsId.get());
		rgd.setRoomNo(roomNo.get());
		rgd.setRegisterTime(registerTime.get());
		rgd.setValid(valid.get());
		rgd.setComment(comment.get());
		return rgd;
	}
	
	public RoomGoods(RoomGoods roomGoods, int goodsId, String name, double price, String describe) {
		super(goodsId, name, price, describe);
		this.roomGoodsId = new SimpleIntegerProperty(roomGoods.getRoomGoodsId());
		this.roomNo = new SimpleStringProperty(roomGoods.getRoomNo());
		this.registerTime = new SimpleStringProperty(roomGoods.getRegisterTime());
		this.valid = new SimpleBooleanProperty(roomGoods.isValid());
		this.comment = new SimpleStringProperty(roomGoods.getComment());
	}
	
	public RoomGoods(int roomGoodsId, String roomNo, String registerTime, int valid, String comment, 
			int goodsId, String name, double price, String describe) {
		super(goodsId, name, price, describe);
		this.roomGoodsId = new SimpleIntegerProperty(roomGoodsId);
		this.roomNo = new SimpleStringProperty(roomNo);
		this.registerTime = new SimpleStringProperty(registerTime);
		if(valid > 0) this.valid = new SimpleBooleanProperty(true);
		else this.valid = new SimpleBooleanProperty(false);
		this.comment = new SimpleStringProperty(comment);
	}
	
	public RoomGoods(int roomGoodsId, String roomNo, String registerTime, int valid, String comment, Goods goods) {
		super(goods);
		this.roomGoodsId = new SimpleIntegerProperty(roomGoodsId);
		this.roomNo = new SimpleStringProperty(roomNo);
		this.registerTime = new SimpleStringProperty(registerTime);
		if(valid > 0) this.valid = new SimpleBooleanProperty(true);
		else this.valid = new SimpleBooleanProperty(false);
		this.comment = new SimpleStringProperty(comment);
	}
	
	public RoomGoods(RoomGoods roomGoods, Goods goods) {
		super(goods);
		this.roomGoodsId = new SimpleIntegerProperty(roomGoods.getRoomGoodsId());
		this.roomNo = new SimpleStringProperty(roomGoods.getRoomNo());
		this.registerTime = new SimpleStringProperty(roomGoods.getRegisterTime());
		this.valid = new SimpleBooleanProperty(roomGoods.isValid());
		this.comment = new SimpleStringProperty(roomGoods.getComment());
	}
	
	@Override
	public String toString() {
		String str = String.format("RoomGoodsId:%d RoomNo:%s registerTime:%s valid:%s comment:%s", 
				roomGoodsId.get(), roomNo.get(), registerTime.get(), valid.get(), comment.get());
		return str + " " + super.toString();
	}
	
	public final SimpleIntegerProperty roomGoodsIdProperty() {
		return this.roomGoodsId;
	}
	
	public final int getRoomGoodsId() {
		return this.roomGoodsIdProperty().get();
	}
	
	public final void setRoomGoodsId(final int roomGoodsId) {
		this.roomGoodsIdProperty().set(roomGoodsId);
	}
	
	public final SimpleStringProperty roomNoProperty() {
		return this.roomNo;
	}
	
	public final String getRoomNo() {
		return this.roomNoProperty().get();
	}
	
	public final void setRoomNo(final String roomNo) {
		this.roomNoProperty().set(roomNo);
	}
	
	public final SimpleStringProperty registerTimeProperty() {
		return this.registerTime;
	}
	
	public final String getRegisterTime() {
		return this.registerTimeProperty().get();
	}
	
	public final void setRegisterTime(final String registerTime) {
		this.registerTimeProperty().set(registerTime);
	}
	
	public final SimpleBooleanProperty validProperty() {
		return this.valid;
	}
	
	public final boolean isValid() {
		return this.validProperty().get();
	}
	
	public final void setValid(final boolean valid) {
		this.validProperty().set(valid);
	}
	
	public final SimpleStringProperty commentProperty() {
		return this.comment;
	}
	
	public final String getComment() {
		return this.commentProperty().get();
	}
	
	public final void setComment(final String comment) {
		this.commentProperty().set(comment);
	}
}
